package kgc.qy.service.impl;

import kgc.qy.mapper.SysRolesMapper;
import kgc.qy.mapper.SysUsersMapper;
import kgc.qy.pojo.SysRoles;
import kgc.qy.pojo.SysUsers;
import kgc.qy.service.ISysUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysUsersServiceImpl implements ISysUsersService {

    @Autowired
    private SysUsersMapper sysUsersMapper;
    @Autowired
    private SysRolesMapper sysRolesMapper;


    @Override
    public List<SysUsers> selectSysUserByPram(String account,String userName,String Type) {
        Byte userType = 0;
        switch (Type){
            case "系统管理员":
                userType = 1;
                break;
            case "挂号员":
                userType = 2;
                break;
            case "门诊医师":
                userType = 3;
                break;
        }
        List<SysUsers> sysList = sysUsersMapper.selectSysUserByPram(account,userName,userType);
        return sysList;
    }

    @Override
    public List<SysRoles> selectAllRoles() {
        List<SysRoles> sysRoles = sysRolesMapper.selectAll();
        return sysRoles;
    }

    @Override
    public String updateUserStatusById(String userId, String flag) {
        int id = Integer.parseInt(userId);
        int status = 0;
        switch (flag) {
            case "false":
                status = 0;
                break;
            case "true":
                status = 1;
                break;
        }
        int f = sysUsersMapper.updateUserStatusById(id, status);
        if (f > 0) {
            return "true";
        }
        return "false";
    }
}
